﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Modules_IA_Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //    if (Request["status"] == "exit")                                //如果是退出信息
        //        Session["Islogin"] = "";                                    //清楚登录状态
        //    if (Session["Islogin"] == "YES")                                //如果已经登录
        //        Response.Redirect("home.aspx");                             //转到主页
        //    if (Session["ImageUniqueCode"] == null)                         //如果验证码标志为空
        //        Session["ImageUniqueCode"] = "";                            //设置为空字符
        //    this.txtaccount.Focus();
    }

    protected void btnlogin_Click(object sender, EventArgs e)
    {


        string Password = txtpassword.Text.Trim();                      //取得密码
        string Account = txtaccount.Text.Trim();                        //取得用户名


        //if (Password == null || Password == "")
        //{
        //    error.Text = "请输入密码";
        //    error.Visible = true;                                      //显示警告
        //}



        //if (Account == null || Account == "")
        //{
        //    error.Text = "请输入账号";
        //    error.Visible = true;                                      //显示警告
        //}

        string UniqueCode = Session["ImageUniqueCode"].ToString();      //取得验证码
        string InputCode = txtSecurityCode.Text.Trim();                 //取得输入码


        //string sqlstr = "select * from [user] where account='admin'";       //数据库查询语句
        //SqlConnection sqlconn = new SqlConnection();                 //定义数据库连接
        ////设置数据库连接字符串
        //sqlconn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["SerialPortConnectionString"].ConnectionString;
        //try
        //{
        //    sqlconn.Open();              //尝试打开数据库
        //}
        //catch (Exception)               //如果未能打开数据库
        //{
        //    System.Media.SystemSounds.Hand.Play();
        //    Response.Write("<center>未能打开与数据库的连接<center><script type='text/javascript'>alert('未能打开与数据库的连接，数据库连接字符串为：\\n" + sqlconn.ConnectionString + "\\n请与管理员或技术人员联系。')</script>");
        //    Response.End();
        //    return;                     //返回
        //    throw;
        //}
        //SqlCommand sqlcomm = new SqlCommand(sqlstr, sqlconn);           //定义数据库查询
        //SqlDataReader sqldtr = sqlcomm.ExecuteReader();                 //执行查询语句并存储起来
        //while (sqldtr.Read())
        //{
        //    //if (sqldtr["account"].ToString() == Account)                  //如果用户名匹配
        //    if (Account == "admin")                  //如果用户名匹配
        //    {
        //        //if (sqldtr["password"].ToString() == Password)          //如果密码匹配
        //        if (Password == "123")          //如果密码匹配
        //        {
        //            Session["Islogin"] = "yes";
        //            Session["account"] = Account;
        //            Response.Redirect("default.aspx");                     //登录成功
        //        }
        //    }
        //}
        //sqlcomm.Dispose();                                              //释放数据库查询资源
        //sqlconn.Dispose();                                              //释放数据库连接
        //error.Text = "用户名或密码不正确";                              //登录错误

        //if (sqldtr["account"].ToString() == Account)                  //如果用户名匹配
        if (Account == "admin")                  //如果用户名匹配
        {
            //if (sqldtr["password"].ToString() == Password)          //如果密码匹配
            if (Password == "123")          //如果密码匹配
            {
                if (!UniqueCode.Equals(InputCode, StringComparison.CurrentCultureIgnoreCase))    //如果不匹配
                {
                    error.Text = "验证码错误";                                   //显示警告
                    return;                                                     //函数返回
                }
                Session["Islogin"] = "yes";
                Session["account"] = Account;
                Response.Redirect("home.aspx");                     //登录成功
            }

        }
        error.Text = "账号或密码错误";
        return;
    }
}